﻿using pingjia.bll;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class views_customer_Changepassword : System.Web.UI.Page
{
    ConsumerService customeSrv = new ConsumerService();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Unnamed1_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            //调用CustomerService类中的IsNameExist()方法判断输入的用户名是否存在
            if (!customeSrv.IsNameExist(txtName.Text.Trim()))
            {
                Response.Write("<script>alert('用户不存在')</script>");
            }
            else
            {
                //调用CustomerService类中的IsEmailExist()方法判断输入的用户名和邮箱是否存在
                if (!customeSrv.IsEmailExist(txtName.Text.Trim(), txtEmail.Text.Trim()))
                {
                    Response.Write("<script>alert('邮箱不正确')</script>");
                }
                else
                {
                    //调用CustomerService类中的ResetPassword()方法重置用户密码为用户名
                    customeSrv.ResetPassword(txtName.Text.Trim(), txtEmail.Text.Trim());
                    //新建自定义的EmailSender类实例emailSender对象
                    EmailSender emailSender = new EmailSender(txtEmail.Text.Trim(), txtName.Text.Trim());
                    //调用自定义的EmailSender类中的Send()方法发送邮件
                    emailSender.Send();
                    Response.Write("<script>alert('密码已发送至邮箱')</script>");
                }
            }
        }
    }

    protected void Unnamed2_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Login.aspx");
    }
}